Skip to content

perf(web-ui): eliminate WebKit layout/streaming bottlenecks and unify session loading - #3936

Merged
bobleer merged 3 commits into
openBitFun:mainfrom
bobleer:bob/desktop-webview-perf
Nov 16, 2026
Merged

bobleer merged 3 commits into
openBitFun:mainfrom
bobleer:bob/desktop-webview-perf

Conversation

@bobleer

@bobleer bobleer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Targeted desktop WebView (especially macOS WKWebView) and FlowChat performance optimizations — plus unified, calm session-switch loading presentation — addressing full-tree style invalidation, forced synchronous layout thrashing during session/tab/turn navigation, whole-document Markdown streaming fallbacks, memory-budget/persistence heap churn, and visually jarring full-pane session skeleton flashes.

  1. Scoped scrollbar & reset CSS (@openbitfun/ui & AppLayout):

    • Gate legacy universal *::-webkit-scrollbar* rules in design-system/packages/ui/src/styles/scrollbars.css behind @supports not (scrollbar-color: transparent transparent) so modern engines supporting CSS Scrollbars Level 1 skip matching 7 universal pseudo-element rules on every descendant DOM node (-39% transcript remount/layout cost in WKWebView), with updated contract coverage in scroll-area.test.mjs and src/app/styles/scrollbar.test.ts.
    • Rewrite fine-pointer scrollbar reveal selectors via De Morgan equivalence so toggling :root[data-openbitfun-focus-visible] only invalidates :focus-within ancestors instead of :root[...] * across the entire DOM (19.46 ms -> 1.71 ms, -91.2% per pointer/keyboard modality flip).
    • Remove duplicate AppLayout.scss import in AppLayout.tsx (already imported globally in src/app/styles/index.scss) and redundant unlayered !important universal *::before, *::after box-sizing reset.
  2. Eliminate sequential forced synchronous layouts (VirtualMessageList, useFlowChatVirtualizer, useSceneTabNavigation, useTimelineInteraction):

    • Run centerFlowChatExtent (extent.style.left write) after useFlowChatVirtualizer layout reads so publishOriginInset does not trigger a second synchronous full-transcript layout pass; reuse ResizeObserverEntry borderBoxSize and move tabIndex={-1} to JSX.
    • Skip getBoundingClientRect() tab scans in revealPendingTab when the SceneBar tab strip has no horizontal overflow (scrollWidth <= clientWidth at origin), and memoize openTabIds.
    • Split measureRenderedItems into an attribute-write pass followed by a getBoundingClientRect read pass, guard retired-key Set diffing by itemKeyRevision, and skip getBoundingClientRect() in useTimelineInteraction while following live output.
  3. Incremental Markdown streaming & zero-allocation budget/hash walks:

    • Strip closed inline code spans and ignore plain < comparisons in markdownSections so technical responses containing generics (Vec<T>, Result<T, E>) or < comparisons retain 3,000-char section freezing instead of falling back to whole-document re-parsing on every streaming tick.
    • Run rehype-raw (parse5) via rehypeRawIfNeeded only when remark-rehype emits at least one raw HAST node, strip fenced/inline code before mayContainMarkdownMath, include remarkCachedParse for settled math blocks, and reject skipped subtrees at the element level in useStreamingTextReveal.
    • Replace recursive Object.entries tuple allocations in estimateRetainedBytes (5.37 ms -> 1.51 ms, -71.9%) and JSON.stringify in calculateTurnHash with zero-allocation traversals.
  4. Unify session-switch loading indicator with new-session / device-switch curtains (HistorySessionLoadingBoundary):

    • Replace the full-pane fake user-bubble + 7-row shimmer skeleton in HistorySessionLoadingBoundary with the centered muted <Spinner size="md" /> (variant="logo", delayed by 200ms so fast <200ms switches show zero loading flash and go straight to settled content, while slower loads softly fade in to var(--openbitfun-opacity-muted)), matching DeviceSwitchCurtain and removing continuous full-pane mask-shimmer repaints.
    • Preserve historySkeleton, historyOverlay, historyOpenIntent, and hidden historyOpenIntentSpinner Appearance slots, Visual Skin transparent chat artwork rules, and data-history-loading-phase readiness contracts; remove render-phase setState in HistorySessionLoadingBoundary.

Type and Areas

Type: Performance optimization & UI polish

Areas: design-system (@openbitfun/ui), src/web-ui (FlowChat virtualizer, loading boundary & timeline, SceneBar, Markdown pipeline, resource budget & persistence)

Motivation / Impact

Desktop WebView profiling on macOS WKWebView (80-turn multi-tool fixture with 100 tool calls/turn + live loopback SSE streaming, identical native binary run sequentially in isolation) shows substantial latency and frame-drop reductions across interactive scenarios:

Scenario (multi-tool, 80 turns) Metric Baseline Optimized Delta
Focus modality flip (data-openbitfun-focus-visible) Sync style/layout ms 19.46 ms 1.71 ms -91.2% (11.4x)
Transcript remount / width reflow Sync layout ms 15.58 / 15.83 ms 9.46 / 9.63 ms -39.3% / -39.2%
streaming/session-switch P95 latency / RAF FPS 137 ms / 42.5 fps 113 ms / 56.8 fps -17.5% / +33.8%
streaming/session-switch Frame P95 / Max / >33.3ms 64 ms / 88 ms / 20.0% 46 ms / 52 ms / 10.0% -28.1% / -40.9% / -50.0%
streaming/turn-jump P50 latency / RAF FPS 234 ms / 40.9 fps 192 ms / 56.0 fps -17.9% / +36.8%
streaming/turn-jump Frame P95 / Max / >33.3ms 65 ms / 73 ms / 21.1% 39 ms / 49 ms / 7.7% -40.0% / -32.9% / -63.5%
streaming/continuous-scroll-up Frame Max / >33.3ms 87 ms / 12.1% 35 ms / 4.2% -59.8% / -65.1%
streaming/continuous-scroll-down Frame P95 / >33.3ms 31 ms / 4.6% 23 ms / 1.5% -25.8% / -68.2%
static/first-open P95 latency / RAF FPS 193 ms / 44.4 fps 172 ms / 50.2 fps -10.9% / +13.0%
static/session-switch RAF FPS / >33.3ms 39.1 fps / 15.0% 45.2 fps / 10.5% +15.8% / -30.0%
longRoundPerfHarness (300 rounds, 20 flushes) Total / P95 flush 9.18 ms / 1.34 ms 4.03 ms / 0.38 ms -56.1% / -71.6%

Verification

  • pnpm --dir design-system --filter @openbitfun/ui run test — 355/355 passed (including scroll-area.test.mjs scrollbar CSS contracts)
  • pnpm --dir design-system --filter @openbitfun/package-contract run test — 4/4 passed
  • pnpm run check:web (typography audit, appearance contract audit, theme:color-audit:all across 27 surfaces, theme visual governance contract, and tsc --noEmit) — passed
  • pnpm run motion:audit — passed
  • Focused Web UI suites (src/app/styles, HistorySessionLoadingBoundary.test.tsx, ModernFlowChatContainer.history-restore.test.tsx, VirtualMessageList.session-boundary.test.tsx, DeviceSwitchCurtain.test.tsx, headless Chrome history-loading-paint.test.ts, AppearanceRegistry.test.ts, AppearanceCompiler.test.ts, resourceBudget.test.ts, PersistenceModule.test.ts, src/infrastructure/markdown, src/app/components/SceneBar, useTimelineInteraction.test.tsx, DesignSystemViteIntegration.test.ts, WorkspaceBody.presentation.test.ts, useFlowChatVirtualizer*.test.*, VirtualMessageList.session-switch.test.tsx, longRoundPerfHarness.test.tsx) — all passed
  • pnpm run build:web & pnpm --dir src/mobile-web run type-check && pnpm run build:mobile-web — passed
  • pnpm run check:repo-hygiene && node scripts/check-git-object-sizes.mjs --base upstream/main --head HEAD && git diff --check — passed
  • Native desktop E2E benchmarks (node tests/e2e/scripts/run-long-session-performance.mjs --scenario multi-tool --turns 80 --repeats 4 --scroll-steps 40 and --suite streaming-switch --scenario multi-tool --turns 80 --repeats 4) — 24/24 matrix samples and 4/4 streaming-switch samples valid.

Reviewer Notes

  • Remote scenarios: Native E2E benchmarks were exercised on local macOS Desktop (WKWebView), and session-loading/appearance/persistence suites exercised simulated peer-device surface transitions and local headless Chrome Visual Skin paint fixtures; live Remote Workspace, Remote Control, Peer Device Mode, and Detached Dispatch hosts were not exercised end-to-end.
  • AI disclosure: AI-assisted change; fully tested locally across unit/contract suites, repository governance audits, production web & mobile-web bundle verification, headless Chrome Visual Skin paint tests, and native Tauri desktop E2E benchmarks.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable.

@bobleer bobleer changed the title perf(web-ui): eliminate WebKit scrollbar/layout thrashing and streaming overhead perf(web-ui): eliminate WebKit layout/streaming bottlenecks and unify session loading Nov 16, 2026
…ng overhead

Eliminate major desktop WebView (especially macOS WKWebView) frame drops and
synchronous layout/style bottlenecks across session switching, turn navigation,
focus modality transitions, and long streaming conversations without altering
visual streaming cadence or session behavior:

1. Scoped scrollbar & reset CSS for WebKit/Blink:
   - Gate legacy universal `*::-webkit-scrollbar*` rules behind
     `@supports not (scrollbar-color: transparent transparent)` so modern
     engines supporting CSS Scrollbars Level 1 skip matching 7 universal
     pseudo-element rules on every descendant DOM node (~39% faster transcript
     layout/remount in WKWebView).
   - Rewrite fine-pointer scrollbar reveal rules via De Morgan equivalence so
     toggling `:root[data-openbitfun-focus-visible]` only invalidates
     `:focus-within` ancestors instead of `:root[...] *` across the whole DOM
     (19.46 ms -> 1.71 ms per modality flip).
   - Remove duplicate `AppLayout.scss` import in `AppLayout.tsx` and redundant
     unlayered `!important` universal `*::before/*::after` box-sizing reset.

2. Eliminate sequential forced synchronous layouts in FlowChat & SceneBar:
   - Run `centerFlowChatExtent` (`extent.style.left` write) after
     `useFlowChatVirtualizer` layout reads, reuse `ResizeObserverEntry`
     `borderBoxSize` in `publishOriginInset`, and set `tabIndex={-1}` in JSX.
   - Skip `getBoundingClientRect()` DOM scans in `revealPendingTab` when the
     SceneBar tab strip has no horizontal overflow.
   - Split `measureRenderedItems` into an attribute-write pass followed by a
     measurement-read pass, guard key-set diffing by `itemKeyRevision`, and
     skip `getBoundingClientRect()` in `useTimelineInteraction` while following.

3. Incremental Markdown streaming & zero-allocation budget/hash walks:
   - Strip closed inline code spans and ignore plain `<` comparisons in
     `markdownSections` so technical replies (`Vec<T>`, `a < b`) keep 3k-char
     section freezing instead of falling back to whole-document re-parsing.
   - Run `rehype-raw` (`parse5`) only when `remark-rehype` emits `raw` HAST
     nodes, strip code before math detection, enable `remarkCachedParse` for
     settled math blocks, and reject skipped subtrees at the element level in
     `useStreamingTextReveal`.
   - Replace recursive `Object.entries` tuple allocations in
     `estimateRetainedBytes` and `JSON.stringify` in `calculateTurnHash` with
     zero-allocation traversals.
@bobleer
bobleer force-pushed the bob/desktop-webview-perf branch from 4131f30 to 06150dd Compare November 16, 2026 05:37
@bobleer
bobleer merged commit 453b507 into openBitFun:main Nov 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant